package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.CardPartAnalyse;
import com.ruoyi.system.service.ICardPartAnalyseService;
import lombok.Data;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2022-10-23
 */
@Controller
@RequestMapping("/system/analyse")
public class CardPartAnalyseController extends BaseController {
    private String prefix = "system/analyse";

    @Autowired
    private ICardPartAnalyseService cardPartAnalyseService;

    @RequiresPermissions("system:analyse:view")
    @GetMapping("{carId}/{carInfoId}")
    public String analyse(@PathVariable Long carId, @PathVariable Long carInfoId, ModelMap mmap) {
        CardPartAnalyse cardPartAnalyse = new CardPartAnalyse();
        cardPartAnalyse.setCardId(carId);
        cardPartAnalyse.setCardInfoId(carInfoId);
        mmap.put("analyses", cardPartAnalyseService.selectCardPartAnalyseList(cardPartAnalyse));
        return prefix + "/analyse";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:analyse:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CardPartAnalyse cardPartAnalyse) {
        startPage();
        List<CardPartAnalyse> list = cardPartAnalyseService.selectCardPartAnalyseList(cardPartAnalyse);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:analyse:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CardPartAnalyse cardPartAnalyse) {
        List<CardPartAnalyse> list = cardPartAnalyseService.selectCardPartAnalyseList(cardPartAnalyse);
        ExcelUtil<CardPartAnalyse> util = new ExcelUtil<CardPartAnalyse>(CardPartAnalyse.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add/{carId}/{carInfoId}")
    public AjaxResult add(@PathVariable Long carId, @PathVariable Long carInfoId, ModelMap mmap) {CardPartAnalyse cardPartAnalyse = new CardPartAnalyse();
        cardPartAnalyse.setCardId(carId);
        cardPartAnalyse.setCardInfoId(carInfoId);
        cardPartAnalyse.setCreateBy(getLoginName());
        cardPartAnalyse.setCreateTime(new Date());
        cardPartAnalyse.setUpdateBy(cardPartAnalyse.getCreateBy());
        cardPartAnalyse.setUpdateTime(cardPartAnalyse.getCreateTime());
        return toAjax(cardPartAnalyseService.insertCardPartAnalyse(cardPartAnalyse));
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:analyse:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CardPartAnalyse cardPartAnalyse) {
        AjaxResult ajaxResult = toAjax(cardPartAnalyseService.insertCardPartAnalyse(cardPartAnalyse));
        ajaxResult.setData(cardPartAnalyse.getId());
        return ajaxResult;
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("system:analyse:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        CardPartAnalyse cardPartAnalyse = cardPartAnalyseService.selectCardPartAnalyseById(id);
        mmap.put("cardPartAnalyse", cardPartAnalyse);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:analyse:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CardPartAnalyse cardPartAnalyse) {
        return toAjax(cardPartAnalyseService.updateCardPartAnalyse(cardPartAnalyse));
    }

    @Data
    class Analyse {
        private List<Long> id;
        private List<Long> cardId;
        private List<Long> cardInfoId;
        private List<String> content;
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:analyse:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{id}")
    @ResponseBody
    public AjaxResult remove( @PathVariable String id) {
        return toAjax(cardPartAnalyseService.deleteCardPartAnalyseByIds(id));
    }
}
